package com.ews.onlineexchange.service;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.ServiceSupplier;

@Model
public class BestServiceSupplierList extends EntityQuery<ServiceSupplier> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public BestServiceSupplierList() {
		setMaxResults(MAX_RESULTS_FEW);
		setOrder( "creditScore DESC" );
	}

	@Override
	protected List<Predicate> getRestrictions( CriteriaBuilder cb, Root<ServiceSupplier> entity ) {
		List<Predicate> restrictions = super.getRestrictions( cb, entity );
		restrictions.add( cb.isTrue( entity.<Boolean>get( "valid" ) ) );
		restrictions.add( cb.isTrue( entity.<Boolean>get( "auditted" ) ) );
		restrictions.add( cb.isNotNull( entity.get( "creditScore" ) ) );
		return restrictions;
	}

}
